package org.example.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PasswordUtils {
    private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
    
    /**
     * 加密密码
     */
    public static String encode(CharSequence rawPassword) {
        return ENCODER.encode(rawPassword);
    }
    
    /**
     * 校验密码
     * @param rawPassword 用户输入的明文密码
     * @param encodedPassword 数据库存储的加密密码
     */
    public static boolean matches(CharSequence rawPassword, String encodedPassword) {
        return ENCODER.matches(rawPassword, encodedPassword);
    }
}